class Free
  attr_reader :name, :rates, :response_code, :error
  
  def initialize(zip_to, weight, options={})
    # Kinda redundant, but we need to be compatable so
    # return rate right away, we already know it's free
    if options[:service_code] == 'free'
      rates = {
        :service_code => 'Free_free_0.00',
        :service_description => 'Free',
        :charge => 0.00,
        :currency_code => 'USD'
      }
      return rates
    end
    
    yaml = YAML.load(File.new("#{RAILS_ROOT}/config/shipping_rate.yml"))
    
    free_shipping_config = yaml['free_shipping']
    @name = free_shipping_config['name']
    @order_minimum = free_shipping_config['order_minimum']
    @order_total = options[:total] || 0
    @rates = get_rates
  end
  
  def get_rates
    rates = []
    if @order_total >= @order_minimum
      rates << {
        :service_code => 'Free_free_0.00',
        :service_description => 'Free',
        :charge => 0.00,
        :currency_code => 'USD'
      }
      return rates
    else
      @error = "Order must be at least #{@order_minimum}"
      return nil
    end
    
  end
end